package GameObjects;


public class AutoMovingPaddle extends AbstractPaddle{

	private static final long serialVersionUID = 289930522003926247L;
	
	PaddleDirection direction;
	int speed;
	int windowHeight;
	
	public AutoMovingPaddle(int x, int y, int width, int height, int speed, int windowHeight, PaddleDirection pd){
		super(x, y, width, height);
		this.speed = speed;
		this.windowHeight = windowHeight;
		this.direction = pd;
	}
	
	//separate this from update
	public void moveUp(int amount) {
		double x = this.getX();
		double y = this.getY();
		y-=amount;
		this.setLocation( (int)x, (int) y);	
	}

	public void moveDown(int amount) {
		double x = this.getX();
		double y = this.getY();
		y+=amount;
		this.setLocation( (int)x, (int) y);	
	}

	@Override
	public void updateState() {
		double y = this.getY();
		double height = this.getHeight();
		
		
		if(direction.equals(PaddleDirection.UP)){
			if(y <= 0){
				direction = PaddleDirection.DOWN;
				this.moveDown(speed);
			}else{
				this.moveUp(speed);
			}
		}else{	
			if( (y+height) >  (double)windowHeight){
				direction = PaddleDirection.UP;
				moveUp(speed);
			}else{
				moveDown(speed);
			}
		}	
	}	
	
	@Override
	public void move(){
		setLocation(x, y);
	}

}
